
  <!-- 内容区域 -->
  <div class="content-wrapper">
    <!-- 内容标题 -->
    <section class="content-header">
        <h1>
            <small>素材管理</small>/添加<?= $material_title?>
        </h1>
        <ol class="breadcrumb display-none">
            <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li><a href="#">生成</a></li>
            <li class="active">添加</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content pd-top0">
        <div class="row">
            <!-- left column -->
            <div class="col-md-12">
                <div class="box">
                    <div class="box-body solist">
                        <div class="detail-page-sy">
                            <form class="form-horizontal" action="<?=base_url()?>index.php/admin/material/store" method="post" id='CreateForm'>
                                <div class="detail-page-border">
                                    <!-- <div class="detail_title">
                                        商品信息
                                    </div> -->
                                    <div class="detail_con">
                                        <div class="form-group hd_title">
                                            <label class="col-sm-2 control-label"><?= $material_title?>名称</label>
                                            <div class="col-sm-4">
                                                <input type="text" class="form-control" placeholder="请输入<?= $material_title?>名称"
                                                    name="material[name]" fld='name' value="<?php echo (isset($name)?$name:'') ?>">
                                            </div>
                                            <div style='color:red;'></div>
                                        </div>
                                        <div class="form-group hd_title">
                                            <label class="col-sm-2 control-label">标签</label>
                                            <div class="col-sm-4">
                                                <input type="text" class="form-control" placeholder="请输入标签名"
                                                    name="material[tagname]" fld='tagname' value="<?php echo (isset($tagname)?$tagname:'') ?>">
                                            </div>
                                            <div style='color:red;'></div>
                                        </div>
                                        <?php if('1' == $material_type){?>
                                        <div class="form-group hd_title">
                                            <label class="col-sm-2 control-label">缩略图地址</label>
                                            <div class="col-sm-4">
                                                <input type="text" class="form-control" placeholder="请输入缩略图地址"
                                                    name="material[thumbnail]" fld='thumbnail' value="<?php echo (isset($thumbnail)?$thumbnail:'') ?>">
                                            </div>
                                            <div style='color:red;'></div>
                                        </div>
                                        <?php }?>
                                        <?php if('yes' == $is_admin){?>
                                            <div class="form-group hd_title">
                                                <label class="col-sm-2 control-label">品牌：</label>
                                                <div class="col-sm-4">
                                                    <select name="material[brand_id]" fld='brand_id' style='width:150px;' class='form-control'>
                                                        <option value="">请选择</option>
                                                        <?php
                                                        foreach ($brand_opts as $key => $opts) {
                                                        ?>
                                                            <option value="<?=$opts['id'] ?>" <?php if(isset($brand_id) && $brand_id == $opts['id']) echo 'selected';?>><?=$opts['name'] ?></option>
                                                        <?php
                                                        }
                                                        ?>
                                                    </select>
                                                </div>
                                                <div style='color:red;'></div>
                                            </div>
                                        <?php }?>
                                        <div class="form-group hd_title">
                                            <label class="col-sm-2 control-label">上传<?= $material_title?></label>
                                            <div class="col-sm-4">
                                                <div class="cover-area" style="padding: 5px 0px;">
                                                    <div class="oh z cover-hd">
                                                       <iframe src="<?=base_url()?>index.php/admin/material/upload" class="uploadfile" style="filter:alpha(opacity = 0);-moz-opacity:0;-khtml-opacity:0;opacity:0;position:absolute;top:5px;left:15px;cursor: pointer;width:120px;height:36px;" id="imgUpload"></iframe> <a href="javascript:;" class="btn btn-default btn-big">+上传<?= $material_title?></a>
                                                    </div><br>
                                                    <p class="cover-bd" id="imgArea" style="display: none;">
                                                        <img id="picurl" src="" width="150" height="70">&nbsp;
                                                        <a id="delImg" class="vb cover-del" href="javascript:;" lang>删除</a>
                                                    </p>
                                                    <p class="cover-bd" id="videoArea" style="display: none;">
                                                        <video width="320" height="240" controls autoplay>

                                                        </video>&nbsp;
                                                        <a id="delVideo" class="vb cover-del" href="javascript:;" lang>删除</a>
                                                    </p>
                                                </div>
                                            </div>
                                            <div style='color:red;' id='img_error_div'></div>
                                        </div>
                                    </div><br>
                                    <div class="box-footer align-center">
                                        <input type="hidden" name="material[upload_path]" fld='upload_path' value="<?php echo (isset($upload_path)?$upload_path:'') ?>">
                                        <input type="hidden" name="material[upload_file]" fld='upload_file' value="<?php echo (isset($upload_file)?$upload_file:'') ?>">
                                        <input type="hidden" name="material[upload_name]" fld='upload_name' value="<?php echo (isset($upload_name)?$upload_name:'') ?>">
                                        <input type="hidden" name="material[upload_type]" fld='upload_type' value="<?php echo (isset($upload_type)?$upload_type:'') ?>">
                                        <input type="hidden" name="material[upload_size]" fld='upload_size' value="<?php echo (isset($upload_size)?$upload_size:'') ?>">
                                        <input type="hidden" name="material[upload_url]" fld='upload_url' value="<?php echo (isset($upload_url)?$upload_url:'') ?>">
                                        <input type="hidden" name="material[material_type]" fld='material_type' value="<?= $material_type?>">
                                        <input class="btn btn-primary btn-big bg-pink" type="button" value="确定" id='submitBtn'>
                                        <a href="<?=base_url()?>index.php/admin/material/index" class="btn btn-default btn-big">取消</a>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <!--/.col (left) -->
        </div>
        <!-- /.row -->
    </section>
    <!-- /.content -->
  </div>
<!-- ./wrapper -->

<script type="text/javascript">
// var pageMenu = {"active": [2]};
var material_title = "<?= $material_title?>";
var material_type = "<?= $material_type?>";
$(function() {
    //删除图片
    $("#delImg").on("click",function(){
        $('.oh').show();
        $('#picurl').attr('src','');
        $('#imgArea').hide();
        $('#CreateForm input[fld=upload_path]').val('');
        $('#CreateForm input[fld=upload_file]').val('');
        $('#CreateForm input[fld=upload_name]').val('');
        $('#CreateForm input[fld=upload_type]').val('');
        $('#CreateForm input[fld=upload_size]').val('');
        $('#CreateForm input[fld=upload_url]').val('');
    });
    //删除视频
    $("#delVideo").on("click",function(){
        $('#videoArea').hide();
        $('#videoArea > video > source').attr('src','');
        $('#videoArea > video > source > object').attr('data','');
        $('#videoArea > video > source > object > embed').attr('src','');
        $('#CreateForm input[fld=upload_path]').val('');
        $('#CreateForm input[fld=upload_file]').val('');
        $('#CreateForm input[fld=upload_name]').val('');
        $('#CreateForm input[fld=upload_type]').val('');
        $('#CreateForm input[fld=upload_size]').val('');
        $('#CreateForm input[fld=upload_url]').val('');
    });

    var is_submit = 1;
    $('#submitBtn').on('click',function(){
        var idx = 1;
        $('#CreateForm input[fld=name]').val($.trim($('#CreateForm input[fld=name]').val()));
        if($('#CreateForm input[fld=name]').val() == ''){
            $('#CreateForm input[fld=name]').parent().next().html('请输入'+material_title+'名称。');
            idx = 0;
        }else{
            $('#CreateForm input[fld=name]').parent().next().html('');
        }
        if($('#CreateForm select[fld=brand_id]').length > 0){
            if($('#CreateForm select[fld=brand_id]').val() == ''){
                $('#CreateForm select[fld=brand_id]').parent().next().html('请选择品牌。');
                idx = 0;
            }else{
                $('#CreateForm select[fld=brand_id]').parent().next().html('');
            }
        }
        if($('#CreateForm input[fld=upload_url]').val() == ''){
            $('#img_error_div').html('请选择要上传的'+material_title);
            idx = 0;
        }else{
            $('#img_error_div').html('');
        }
        if(0 == idx){
            return false;
        }
        if(1 != is_submit){
            return false;
        }
        is_submit = 2;
        $('#CreateForm').submit();
    });

    // url = 'http://localhost/project/mzadmin/upload/2017/03/06/17030610280958168585.mp4';
    // $('#videoArea').show();
    // $('#videoArea > video > source').attr('src',url);
    // $('#videoArea > video > object').attr('data',url);
    // $('#videoArea > video > object > embed').attr('src',url);
    // $('#videoArea > video').html('<source src="'+url+'" type="video/ogg">'+
    //                                 '<source src="'+url+'" type="video/mp4">'+
    //                                 '<source src="'+url+'" type="video/webm">'+
    //                                 '<object data="'+url+'" width="320" height="240">'+
    //                                     '<embed width="320" height="240" src="'+url+'">'+
    //                                 '</object>')
})

//图片上传
function updataImg(url){
    $('#imgArea').show();
    $('#picurl').attr('src',url);
}
function updataVideo(url){
    $('#videoArea').show();
    $('#videoArea > video').html('<source src="'+url+'" type="video/ogg">'+
                                    '<source src="'+url+'" type="video/mp4">'+
                                    '<source src="'+url+'" type="video/webm">'+
                                    '<object data="'+url+'" width="320" height="240">'+
                                        '<embed width="320" height="240" src="'+url+'">'+
                                    '</object>');
}
//图片上传
function uploadCallBack(upload_path,upload_file,upload_name,upload_type,upload_size,upload_url){
    $('#CreateForm input[fld=upload_path]').val(upload_path);
    $('#CreateForm input[fld=upload_file]').val(upload_file);
    $('#CreateForm input[fld=upload_name]').val(upload_name);
    $('#CreateForm input[fld=upload_type]').val(upload_type);
    $('#CreateForm input[fld=upload_size]').val(upload_size);
    $('#CreateForm input[fld=upload_url]').val(upload_url);
    if(1 == material_type){
        updataVideo(upload_url);
    }else{
        updataImg(upload_url);
    }
}
var error_code = "<?= (isset($error_code)?$error_code:'')?>";
if(error_code != ''){
    $('#CreateForm input[fld=name]').parent().next().html(error_code);
    var upload_url = $('#CreateForm input[fld=upload_url]').val();
    if(1 == material_type){
        updataVideo(upload_url);
    }else{
        updataImg(upload_url);
    }
}
</script>
